<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px" @submit.native.prevent="submitForm">
      <el-form-item label="学号" prop="sno">
        <el-input v-model="form.sno"></el-input>
      </el-form-item>
      <el-form-item label="姓名" prop="sname">
        <el-input v-model="form.sname"></el-input>
      </el-form-item>
      <el-form-item label="年龄" prop="sage">
        <el-input v-model="form.sage"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import axios from 'axios';

export default {
  data() {
    return {
      form: {
        sno: '',
        sname: '',
        sage: '',
      },
    };
  },
  methods: {
    async submitForm() {
      // try {
      this.$axios.post('http://localhost:8080/student/studentInser', this.form
        , {
          headers: {
            'token': localStorage.getItem('token'),
            'Content-Type': 'application/json'
          }
        }
      )
        .then(response => {
          console.log('response', response);
          if (response.data == null || response.data == '') {
            this.$message.error('新增失败');
          } else {
            this.$message.success('新增成功');
          }
        })
        .catch(error => {
          console.log('error', error);
        });




      //   const response = await axios.post('http://localhost:8080/student/studentInser', this.form,
      //     {
      //       headers: {
      //         'token': localStorage.getItem('token'),
      //         'Content-Type': 'application/json'
      //       },
      //     });
      //   if (response.data.success) {
      //     this.$message.success('学生信息添加成功');
      //     this.resetForm();
      //   } else {
      //     this.$message.error('学生信息添加失败');
      //   }
      // } catch (error) {
      //   console.log('error', error);
      //   this.$message.error('请求失败，请检查网络连接');
      // }
    },
    // resetForm() {
    //   this.$refs.form.resetFields();
    // },
  },
};
</script>
<style scoped>
.main_top_left_top_con {
  width: 100%;
  height: 100%;
}

.b1 {
  height: 50px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.3s ease;
}

.b1:active {
  transform: scale(1.5);
  /* 点击时放大1.1倍 */
}

.b1:hover {
  background-color: rgb(0, 26, 255);
  color: white;
}

.rightTitle {
  position: fixed;
  right: 0;
  height: 100%;
  width: 152px;
  background-color: rgb(173, 173, 173);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.a1 {
  display: flex;
  width: 100%;
}

#publicityId,
#publicityId1 {
  background-color: black;
  /* margin-left: 100px; */
  width: 30%;
  padding: 20px;
}
</style>